<?php
/**
 * Created by PhpStorm.
 * User: 跳梁
 * Date: 2016/8/24
 * Time: 17:52
 */

class PersonCenterAction extends Action{
    public function savePersonConfig($id=null,$personHomePic=null,$registerExplainPic=null,$menuJson=null){
        $retVal = Session::init();
        if (!$retVal) {
            Output::instance()->resultCode(code_access_denied);
            return;
        }
        $cid = Session::$user["customerId"];
        Session::switchCustomer(0);
        $personCenter = M("module_person_center");
        Session::switchCustomer($cid);
        $data['cId']=$cid;
        $data['personHomePic']=$personHomePic;
        $data['registerExplainPic']=$registerExplainPic;
        $data['menuJson']=$menuJson;
        $data['updateTime']=date("Y-m-d H:i:s");
        if($id){
            $result = $personCenter->where("id=$id")->save($data);
            $sql = $personCenter->getLastSql();
            if($result!==false){
                R('Log/add',array('newPersonCenter', '', '个人中心设置', op_update, $sql, '更新手机端个人中心设置'));
                Output::instance()->resultCode();
                return;
            }
        }else{
            $data['createTime']=date("Y-m-d H:i:s");
            $result= $personCenter->add($data);
            $sql = $personCenter->getLastSql();
            if($result){
                R('Log/add',array('newPersonCenter', '', '个人中心设置', op_update, $sql, '更新手机端个人中心设置'));
                Output::instance()->resultCode();
                return;
            }
        }
        Output::instance()->resultCode(code_sql_error);
    }
    public function getPersonConfig(){
        $retVal = Session::init();
        if (!$retVal) {
            Output::instance()->resultCode(code_access_denied);
            return;
        }
        $cid = Session::$user["customerId"];
        Session::switchCustomer(0);
        $personCenter = M("module_person_center");
        Session::switchCustomer($cid);
        $personInfo = $personCenter->where("cId=$cid")->find();
        if($personInfo){
            $personInfo['menuJson']=json_decode($personInfo['menuJson'],true);
        }
//        $personInfo['personHomeUrl'] = 'call.html?userName=&customerId=3&module=personCenter&method=index';
        $personInfo['personHomeUrl'] = R('Purse/getPhoneUrl', array('personCenter', 'index'));
        $personInfo['headUrl'] = R('MiContent/getH5ServerHost');
        Output::instance()->object($personInfo);

    }
}